<?php
// select uid from uinfo group by uid having count(uid) >1 ORDER BY `uinfo`.`uid` ASC
//select phone from uinfo where fen > 0 group by phone having count(phone) >1 ORDER BY `uinfo`.`phone` ASC
set_time_limit(0); 
include '../c/config.php';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}

$in=" '11111111111','13002179965','13024111531','13044106369','13072171785','13073283913','13116658674','13120777836',
'13122205576','13122214671','13122579555','13122680608','13162062162'

 ";
 
$j=0;
$query=$mysqli->query("select phone from uinfo where phone not in (".$in.") and quchong is NULL group by phone having count(phone) >1");
while ($list=$query->fetch_array()) {
      $phone=$list['phone'];

      echo  $phone;
      echo "<br /><br />";
     
     $queryD=$mysqli->query("select * from uinfo WHERE phone ='".$phone."' and quchong is NULL  ");
     
     $a=$b=$c=array();
     $i=1;
     while ($listD=$queryD->fetch_assoc()) {
          var_dump($listD);
           echo "<br /><br />";
        if(1 == $i){
           $a=$listD;
        }
        if(2 == $i){
           $b=$listD;	
        }
        if(3 == $i){
           $c=$listD;	
        }
        $i++;
        
        if (0 == $listD['fen']) {
        	$sql="update uinfo set quchong='3' where id='".$listD['id']."' ";
	        echo $sql;
	        $mysqli->query($sql);
             echo "<br /><br />";
        }

     }
     
     if (!empty($b)) {
     	 if ($b['name'] == $a['name'] 
     	 	&&
     	 	$b['phone'] == $a['phone']
     	 	&&
     	 	$b['nianji'] == $a['nianji']
     	 	&&
     	 	$b['school'] == $a['school']
     	 	 ) {
     	 	 
     	 	 echo "b: ",$b['id'];
            
            if ($b['fen'] <  $a['fen']) {
            	echo "<br /><br />";
	     	 	$sql="update uinfo set quchong='2' where id='".$b['id']."' ";
	             echo $sql;
            }else{
            	echo "<br /><br />";
	     	 	$sql="update uinfo set quchong='2' where id='".$a['id']."' ";
	             echo $sql;
            }

     	 	


             $mysqli->query($sql);
             echo "<br /><br />";
     	 }

     	 if ($b['name'] != $a['name'] ){

             $sql="update uinfo set quchong='name' where id='".$a['id']."' ";
	         echo $sql;
	         $mysqli->query($sql);
             echo "<br /><br />";
     	 }


     }

?>
<script type="text/javascript">
    window.setTimeout(function(){
         window.location.reload();
    }, 400);

</script>
<?php
   
    exit;
}

?>